package servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

// 第一种响应方式
@WebServlet("/fourth")
public class FourthServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        System.out.println("FourthServlet service");
        // 获取其他对象 out config session application
        HttpSession session = request.getSession();
        ServletContext application = session.getServletContext();
        PrintWriter out = response.getWriter();
        ServletConfig config = getServletConfig();
        // 向三个容器存放内容
        request.setAttribute("A", "request内容");
        session.setAttribute("B", "session内容");
        application.setAttribute("C", "application内容");
        // 响应 跳转方式
        request.getRequestDispatcher("1.jsp").forward(request, response);
        // response.sendRedirect("1.jsp");
    }
}
